<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增数据配置')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">

    <form class="form-horizontal m" id="addForm"  style="border: 0px solid red;">


        <div class="form-group">
            <label class="col-sm-3 control-label is-required">优先级：</label>
            <div class="col-sm-9">
                <input type="text" name="priority" class="form-control" placeholder="请输入优先级" value="1">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">描述：</label>
            <div class="col-sm-9">
                <input type="text" name="dataDesc" class="form-control" placeholder="请输入描述">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-9">
                <select id="status" name="status" class="form-control">
                    <option value="1">开启</option>
                    <option value="0">关闭</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">环境：</label>
            <div class="col-sm-9">
                <select type="text" name="envCode" id="envCode" class="form-control" >
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">应用：</label>
            <div class="col-sm-9">
                <select type="text" name="appCode" id="appCode" class="form-control" >
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">模板：</label>
            <div class="col-sm-9">
                <select type="text" name="templateKey" id="templateKey" >
                </select>
            </div>
        </div>

        <input type="hidden" name="releaseType" value="3" >
        <div id="dynamicDiv">

        </div>

        <div  style="height: 50px;border: 0px;">
        </div>

    </form>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: summernote-js" />
<script th:src="@{/js/dynamic-data.js}"></script>
<script type="text/javascript">

    function groupHide(id) {
        $("#"+id).parent().parent().hide();
    }
    function groupShow(id) {
        $("#"+id).parent().parent().show();
    }
    groupShow("envCode");
    groupShow("appCode");
    groupShow("templateKey");


    var envCode = getQuery("envCode");
    if (envCode){
        groupHide("envCode");
    }
    common.loadEnv("envCode",envCode);
    $('#envCode').select2({
        allowClear: false
    });

    var appCode = getQuery("appCode");
    if (appCode){
        groupHide("appCode");
    }
    common.loadApp("appCode",appCode);
    $('#appCode').select2({
        allowClear: false
    });

    var templateKey = getQuery("templateKey");
    if (templateKey && templateKey!=null){
        groupHide("templateKey");
    }
    common.loadTemplate("templateKey",templateKey,appCode);
    $('#templateKey').select2({
        allowClear: false
    });

    $("#appCode").on("change",function () {
        var appCode = $("#appCode").val();
        common.loadTemplate("templateKey","",appCode);
    })


    initProperty(appCode,templateKey,"","dynamicDiv");



    var prefix = ctx + "m/dynamic/data/";
    $("#addForm").validate({
        onkeyup: false,
        rules: {
            envCode:{
                required: true,
            },
            appCode:{
                required: true,
            },
            templateKey:{
                required: true,
            },
            priority:{
                required: true,
                number: true,
                maxlength:4
            },
            dataDesc:{
                required: true,
                minlength: 2,
                maxlength:32
            }
        },
        messages: {

        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#addForm").serializeJson();
            getTempJson(function (json) {
                data.tempJson = json;
            });
            if (!data.tempJson){
                return;
            }
            $.operate.save(prefix + "/insert", data,null,true);
        }
    }
</script>
</body>
</html>